package 笔试.two;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

import static MyUtils.MHUtils.can;
import static MyUtils.MHUtils.r;

public class Main {

    static int n;
    static int[] nums;
    static int resMax=-1;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n=sc.nextInt();
        nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i]=sc.nextInt();
        }
        System.out.println(back(0, 0, 0));
    }

    static String erjinzhi(int x){
        StringBuilder sb = new StringBuilder();
        while(x!=0){
            sb.append(x%2);
            x/=2;
        }
        return sb.reverse().toString();
    }

    static boolean comp(int tmp,int c){
        char[] s1 = erjinzhi(tmp).toCharArray();
        char[] s2 = erjinzhi(c).toCharArray();
        if(s2.length>s1.length)return false;
        for (int i=s1.length-1,j=s2.length-1; i>=0&&j>=0; i--,j--) {
            if(s2[j]=='1' && s1[i]=='0'){
                return true;
            }
        }
        return false;
    }
    static Map<String,Integer> map = new HashMap<>();

        static int back(int ci, int step, int tmp) {
        can("ci:"+ci+","+"step:"+step+","+"tmp:"+tmp);
        String key = ci+","+step+","+tmp;
        if(ci==n || step==Math.min(30,n)){
            r("");
            return 0;
        }

        if(map.containsKey(key)){
            return map.get(key);
        }
        int curMax=tmp;
        for (int i = ci; i < nums.length; i++) {
            if(comp(tmp,nums[i]))continue;
            int T = tmp;
            tmp |= nums[i];
            curMax=Math.max(curMax, tmp| back(i+1,step+1,tmp));
            tmp = T;
        }
        map.put(key,curMax);
        r(curMax+";");
        return curMax;
    }
}
